<?php
require 'indeed-php-master/src/indeed.php';
		

function getJob($ville, $cle){

$client = new Indeed("1836689623793436");


$params = array(
    "q" => $cle,
    "l" => $ville,
    "co" =>"FR",
    "sort"=>"relevance",
    "radius"=>100,
    "start"=>0,
    "limit"=>50,
    "end"=>100,
    "userip" => "1.2.3.4",
    "useragent" => "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36",
    "format" => "json",
    "latlong"=>1

);


$results = $client->search($params);



return $results['results'];
}

		if(isset($_GET['ville'])){
			$cle = $_GET['cle'];

		$listJob= getJob($_GET['ville'], $cle);
			//$listJob = getJob("Paris");

	$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$_GET['ville'].',+France&sensor=false');

	$output= json_decode($geocode);

	$lat = $output->results[0]->geometry->location->lat;
	$long = $output->results[0]->geometry->location->lng;
			$message= '{ "information":[';

			foreach($listJob as $d){
		
				$message .='{
				"jobtitle":    "'.$d["jobtitle"].'",
				"latitude":    "'.$d["latitude"].'",
				"longitude":   "'.$d["longitude"].'",
				"company":     "'.$d["company"].'",
				"lieu":        "'.$d["formattedLocationFull"].'"
			},';

				}
			$res = rtrim($message, ",");
			$res .='],
			"latVille": "'.$lat.'",
			"longVille": "'.$long.'"}';
	
	

		echo json_encode($res);
	}


?>